package com.atelier.plugin.database.domain;

import com.atelier.plugin.projectWizard.util.ICONS;

import javax.swing.Icon;


public enum DatabaseType {
    ORACLE("ORACLE", "Oracle","oracle.jdbc.OracleDriver",
            "jdbc:oracle:thin:@%s:%s/%s",
            "ojdbc6.jar",
            Icons.DB_ORACLE, Icons.DB_ORACLE_LARGE,1521),
    MYSQL("MYSQL", "MySQL", "com.mysql.jdbc.Driver",
            "jdbc:mysql://%s:%s/%s?useUnicode=true&useSSL=false&characterEncoding=%s"
            ,"mysql-connector-java-5.1.38.jar",
            ICONS.MYSQL, Icons.DB_MYSQL_LARGE,3306),

    MySQL_8("MYSQL", "MySQL","com.mysql.cj.jdbc.Driver",
            "jdbc:mysql://%s:%s/%s?serverTimezone=UTC&useUnicode=true&useSSL=false&characterEncoding=%s",
            "mysql-connector-j-8.0.33.jar",
            ICONS.MYSQL, Icons.DB_MYSQL_LARGE,3306
    ),
    POSTGRES("POSTGRES", "PostgreSQL","org.postgresql.Driver",
            "jdbc:postgresql://%s:%s/%s", "postgresql-9.4.1209.jar",
            Icons.DB_POSTGRESQL, Icons.DB_POSTGRESQL_LARGE,5432),

    UNKNOWN("UNKNOWN", "Unknown","Unknown","Unknown","Unknown", null, null,null);

    private String name;
    private String displayName;
    private Icon icon;
    private Icon largeIcon;

    private final String driverClass;
    private final String connectionUrlPattern;

    private final Integer defaultPort;

    public void setName(String name) {
        this.name = name;
    }

    public void setDisplayName(String displayName) {
        this.displayName = displayName;
    }

    public void setIcon(Icon icon) {
        this.icon = icon;
    }

    public void setLargeIcon(Icon largeIcon) {
        this.largeIcon = largeIcon;
    }

    public Integer getDefaultPort() {
        return defaultPort;
    }

    public String getDriverClass() {
        return driverClass;
    }

    public String getConnectionUrlPattern() {
        return connectionUrlPattern;
    }

    public String getConnectorJarFile() {
        return connectorJarFile;
    }

    private final String connectorJarFile;
    DatabaseType(String name, String displayName,String driverClass,String connectionUrlPattern,
                 String connectorJarFile,   Icon icon, Icon largeIcon,Integer defaultPort) {
        this.name = name;
        this.displayName = displayName;
        this.icon = icon;
        this.largeIcon = largeIcon;
        this.connectionUrlPattern=connectionUrlPattern;
        this.driverClass=driverClass;
        this.connectorJarFile=connectorJarFile;
        this.defaultPort=defaultPort;
    }

    public String getName() {
        return name;
    }

    public String getDisplayName() {
        return displayName;
    }

    public Icon getIcon() {
        return icon;
    }

    public Icon getLargeIcon() {
        return largeIcon;
    }

    public static DatabaseType get(String name) {
        for (DatabaseType databaseType : values()) {
            if (name.equalsIgnoreCase(databaseType.name)) return databaseType;
        }
        return null;
    }
}
